package com.sywb.chuangyebao.contract;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;

import org.bining.footstone.utils.SharedUtils;

/**
 * 开始界面的Contract
 */
public interface ForgetPwdContract {

    /**
     * 开始界面要实现的View
     */
    interface View extends BaseTokenContract.View {
    }

    /**
     * 开始界面要绑定的Presenter
     */
    class Presenter extends BaseTokenContract.Presenter<View> {

        @Override
        public void onStart() {
            // super.onStart();
        }

        public void resetPassword(String mobile, String password, String code) {
            SharedUtils.put(Constants.USERACCOUNT, mobile);
            SharedUtils.put(Constants.USERPASSWORD, password);
            SharedUtils.put(Constants.USERCAPTCHA, code);

            HttpUtils.resetPassword(new HttpCallback<Object>() {
                @Override
                public void onStart() {
                    super.onStart();
                    onStartAsync();
                }

                @Override
                public void onSuccess(Object userInfo) {
//                    DbManager.getInstance().save(userInfo);
//                    SharedUtils.put(Constants.USEROPENID, userInfo.uid);
//                    SharedUtils.put(Constants.USERACCESSTOKEN, userInfo.access_token);
//                    SharedUtils.put(Constants.USERAUTHTOKEN, userInfo.token);
//                    SharedUtils.put(Constants.USERAUTHTOKENSIG, userInfo.token_sig);
//
//                    SharedUtils.put(Constants.USERISLOGIN, true);
//
//                    RxBus.get().post(Constants.USERISLOGIN, "true");
                    showMessage("设置成功!");
                    mView.exit();
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    showMessage(strMsg);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                    onFinishAsync();
                }
            });
        }

    }
}

